MCU=at90usb162
F_CPU=16000000

UISP = avrdude -c stk500v2 -P avrdoper -B 1 -p $(MCU) 
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) -mmcu=$(MCU)
OBJECTS = 3DPro.o 3DProasm.o main.o usb_hid.o usbdescr.o

LFUSE=0xDE
HFUSE=0xDB
EFUSE=0xF4

# symbolic targets:
all:	clean 3DPVert.hex

.c.o:
	$(COMPILE) -Wa,-adhlns=$(<:.c=.lst) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -Wa,-adhlns=$(<:.S=.lst),-gstabs -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -Wa,-adhlns=$(<:.c=.lst) -S $< -o $@

clean:
	rm -f $(OBJECTS) 3DPro.lst 3DProasm.lst main.lst usb_hid.lst usbdescr.lst 3DPVert.bin 3DPVert.hex 3DPVert.map main.lst

hex: 3DPVert.hex

# file targets:
3DPVert.bin:	$(OBJECTS) 
	$(COMPILE) -o 3DPVert.bin $(OBJECTS) -Wl,-Map=3DPVert.map

3DPVert.hex:	3DPVert.bin
	rm -f 3DPVert.hex 3DPVert.eep.hex
	avr-objcopy -j .text -j .data -O ihex 3DPVert.bin 3DPVert.hex
	avr-size -C --mcu=$(MCU) 3DPVert.bin

flash:	all
	$(UISP) -U flash:w:3DPVert.hex:i

fuse:
	$(UISP) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
